Page({
  data: {
    isLoggedIn: false,
    username: '',
    password: ''
  },
  onLoad: function() {
    // 从 storage 中获取登录状态
    const isLoggedIn = wx.getStorageSync('isLoggedIn');
    this.setData({
      isLoggedIn: isLoggedIn || false
    });
  },
  bindUsernameInput: function(e) {
    this.setData({
      username: e.detail.value
    });
  },
  bindPasswordInput: function(e) {
    this.setData({
      password: e.detail.value
    });
  },
  formSubmit: function(e) {
    const { username, password } = e.detail.value;
    // 这里简单模拟登录验证，假设用户名和密码都是 test
    if (username === 'test' && password === 'test') {
      // 登录成功，存储登录状态到 storage
      wx.setStorageSync('isLoggedIn', true);
      this.setData({
        isLoggedIn: true
      });
    } else {
      wx.showToast({
        title: '用户名或密码错误',
        icon: 'none'
      });
    }
  }
});